package com.eax.ModelLayer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ArrayList;

public class LendCollectionModel {
	private ArrayList<LendModel> lendCollection;

	public LendCollectionModel(){
		lendCollection = new ArrayList<LendModel>();
	}

	public LendModel getLendById(int id){
		LendModel lend = null;

		for(LendModel l : lendCollection){
			if(l.getId() == id){
				lend = l;
			}
		}

		return lend;
	}

	public void printAllLends(){
		for(LendModel l : lendCollection){
			l.printInfo();
			System.out.println();
		}
	}

	public void addLend(int id, int copySerialNumber, int personId, String startDate, String returnDate, String lendingPeriodStart, String lendingPeriodReturn, String status){
		LendModel newLend = new LendModel(id, copySerialNumber, personId, startDate, returnDate, lendingPeriodStart, lendingPeriodReturn, status);
		lendCollection.add(newLend);
	}

	public void returnLend(int id){
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Date date = new Date();

		LendModel lend = getLendById(id);
		lend.setStatus("returned");
		lend.setReturnDate(date.toString());
	}

	public int getSize(){
		return lendCollection.size();
	}

	public ArrayList<LendModel> getAllLends(){
		return lendCollection;
	}

}